package com.climb.moive.service.impl;

import com.climb.moive.dao.MemberDao;
import com.climb.moive.dao.impl.MemberDaoImpl;
import com.climb.moive.entity.Member;
import com.climb.moive.exception.ApplicationException;
import com.climb.moive.service.MemberService;

import java.sql.SQLException;
import java.util.List;

/**
 * @author Administrator
 */
public class MemberServiceImpl implements MemberService {
    MemberDao memberDao=new MemberDaoImpl();
    @Override
    public void insert(Member member) {
        try {
            memberDao.insert(member);
        } catch (SQLException ex) {
            throw new ApplicationException("添加失败", ex);

        }
    }

    @Override
    public Member login(Member member) {
        try {
            return memberDao.login(member);
        } catch (SQLException ex) {
            throw new ApplicationException("登录失败", ex);
        }
    }

    @Override
    public List<Member> findAll() {
        try {
            return memberDao.findAll();
        } catch (SQLException ex) {
            throw new ApplicationException("进入会员管理失败", ex);
        }
    }

    @Override
    public Member findMemberById(Integer id) {
        try {
            return memberDao.findById(id);
        } catch (SQLException ex) {
            throw new ApplicationException("查找用户信息（byid）失败", ex);
        }
    }

    @Override
    public Integer countMember() {
        try {
            return memberDao.count();
        } catch (SQLException throwables) {
            throw new ApplicationException("计算用户数量失败", throwables);

        }
    }

    @Override
    public void update(Member member) {
        try {
            memberDao.update(member);
        } catch (SQLException throwables) {
           throw new ApplicationException("修改用户信息失败",throwables);
        }
    }

    @Override
    public void delet(Integer id) {
        try {
            memberDao.delete(id);
        } catch (SQLException throwables) {
            throw new ApplicationException("删除失败",throwables);
        }
    }

    @Override
    public List<Member> findMembersByName(String name) {
        try {
            System.out.println(name);
            return memberDao.findMembersByName(name);

        } catch (SQLException ex) {
            throw new ApplicationException("进入会员管理失败", ex);
        }
    }


}
